import request from "@/utils/request";
import requestMock from "@/utils/requestMock";
import type { UserInfo, LoginResponse } from "./models";

enum Api {
  getUserInfoUrl = `/admin/acl/index/info`,
  loginUrl = `/admin/acl/index/login`,
  logoutUrl = `/admin/acl/index/logout`,
  getAsyncRoutesUrl = `/admin/acl/permission`,
}

/**
 * 获取用户信息
 * @returns UserInfo
 */
export const getUserInfoApi = () => {
  return request.get<any, UserInfo>(Api.getUserInfoUrl);
};

/**
 * 登录
 * @param username 用户名
 * @param password 密码
 * @returns LoginResponse
 */
export const loginApi = (username: string, password: string) => {
  return request.post<any, LoginResponse>(Api.loginUrl, { username, password });
};

/**
 * 退出登录
 * @returns null
 */
export const logoutApi = () => {
  return request.post<any, null>(Api.logoutUrl);
};

/**
 * 获取动态路由表
 * @returns
 */
export const getAsyncRoutesUrlApi = () => {
  return requestMock.get<any, null>(Api.getAsyncRoutesUrl);
};
